package com.itheima;


import com.itheima.config.SpringConfig;
import com.itheima.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class App {
    public static void main( String[] args ) {
        //AnnotationConfigApplicationContext加载Spring配置类初始化Spring容器
        //读取配置类,处理配置上上所有的注解
        //扫描到ComponentScan,扫描包,创建对象,将对象存入容器
       ApplicationContext ac = new AnnotationConfigApplicationContext(SpringConfig.class);

        //获取容器中所有bean的名称
        String[] beanDefinitionNames = ac.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }


//        按名称获取
//        BookService  bookService = (BookService) ac.getBean("bookService");
//        按类型获取
        BookService bookService = ac.getBean(BookService.class);
        bookService.save();
    }
}
